from apps.account.serializers import UserSerializer
from apps.member.serializers import MemberSerializer
from apps.member.models import Member


def jwt_response_payload_handler(token, user=None, request=None):
    key = 'user'
    if user.is_administrator():
        value = UserSerializer(user, context={'request': request}).data
        value['is_superuser'] = True
    else:
        member = Member.objects.filter(user=user).first()
        value = MemberSerializer(member, context={'request': request}).data
        value['is_superuser'] = False

    return {
        'status': True,
        'token': token,
        key: value
    }
